<?php
class PageView
{
    public function DoSections( $sections, $elements, $editSection = false )
    {
        $html = '';
        
        $html .= '<' . $elements['sectionControlPanel'] . ' class="' . $elements['sectionControlPanelClass'] . '">' . "\r\n";
        
        $html .= '    <form method="post" action="">';
        $html .= '        <fieldset>';
        $html .= '            <label for="addSection_width">Width:</label> <input type="text" name="addSection_width" id="addSection_width" />';
        $html .= '            <input type="submit" name="addSection_option" value="Add Section" />';
        $html .= '        </fieldset>';
        $html .= '    </form>';
            
            
        $html .= '</' . $elements['sectionControlPanel'] . '>' . "\r\n";
        
        $html .= '<' . $elements['sectionWrapper'] . ' class="' . $elements['sectionWrapperClass'] . '">' . "\r\n";
        
        foreach ( $sections as $section )
        {
            $html .= '    <' . $elements['section'] . ' class="' . $elements['sectionClass'] . '" style="width: ' . $section['width'] . ';">' . "\r\n";
            $html .= '    <' . $elements['sectionInner'] . ' class="' . $elements['sectionInnerClass'] . '">' . "\r\n";
            if ( $editSection == $section['sectionid'] ) 
            {
                $html .= '    <!-- START EDITOR --><form method="post" action="" class="wysiwyg">';
                $html .= '        <fieldset>';
                $html .= '            <input type="hidden" name="sectionEdit_sectionID" value="' . $section['sectionid'] . '" />';
                $html .= '            <textarea name="sectionEdit_content">' . $section['content'] . '</textarea>';
                $html .= '            <label for="sectionEdit_width">Width:</label> <input type="text" name="sectionEdit_width" id="sectionEdit_width" value="' . $section['width'] . '" />';
                $html .= '            <input type="submit" name="sectionEdit_option" value="Save Content" />';
                $html .= '        </fieldset>';
                $html .= '    </form><!-- END EDITOR -->';
            }
            else
            {
                $html .= $section['content'];
                
                $html .= '    <' . $elements['sectionOptions'] . ' class="' . $elements['sectionOptionsClass'] . '">' . "\r\n";
                $html .= '    <form method="post" action="">';
                $html .= '        <fieldset>';
                $html .= '            <input type="hidden" name="sectionOptions_sectionID" value="' . $section['sectionid'] . '" />';
                $html .= '            <input type="submit" name="sectionOptions_option" value="Delete Section" disabled="disabled" />';
                $html .= '            <input type="submit" name="sectionOptions_option" value="Edit Content" />';
                $html .= '        </fieldset>';
                $html .= '    </form>';
                $html .= '    </' . $elements['sectionOptions'] . '>' . "\r\n";
            }
            $html .= '    </' . $elements['sectionInner'] . '>' . "\r\n";
            $html .= '    </' . $elements['section'] . '>' . "\r\n";
        }
        
        $html .= '</' . $elements['sectionWrapper'] . '>' . "\r\n";
        
        return $html;
    }

    public function TriedToAddSection()
    {
        return isset( $_POST['addSection_option'] );
    }
    
    public function GetAddSectionWidth()
    {
        return ( isset( $_POST['addSection_width'] ) ) ? $_POST['addSection_width'] : NULL;
    }
    
    
    public function GetSectionOptionsOption()
    {
        return ( isset( $_POST['sectionOptions_option'] ) ) ? $_POST['sectionOptions_option'] : NULL;
    }
    
    public function GetSectionOptionSectionID()
    {
        return ( isset( $_POST['sectionOptions_sectionID'] ) ) ? $_POST['sectionOptions_sectionID'] : NULL;
    }
    
    
    public function GetEditSectionOption()
    {
        return ( isset( $_POST['sectionEdit_option'] ) ) ? $_POST['sectionEdit_option'] : NULL;
    }
    
    public function GetEditSectionSectionID()
    {
        return ( isset( $_POST['sectionEdit_sectionID'] ) ) ? $_POST['sectionEdit_sectionID'] : NULL;
    }
    
    public function GetEditSectionWidth()
    {
        return ( isset( $_POST['sectionEdit_width'] ) ) ? $_POST['sectionEdit_width'] : NULL;
    }
    
    public function GetEditSectionContent()
    {
        return ( isset( $_POST['sectionEdit_content'] ) ) ? $_POST['sectionEdit_content'] : NULL;
    }
}
